import { Context, BaseService } from '../Service'
import { ServiceNo } from '../ServiceNo'
import { isDevMod } from '../../config'
import { addExcludeInterface } from '../impl/AuthService'

class DocService extends BaseService {
  listService (ctx: Context, reqBody: any) {
    const serviceMap: Map<string, BaseService> = ctx.serviceMap
    const serviceInterfaces: any = []
    serviceMap.forEach((service, serviceNo) => {
      service.methodMap.forEach((interfas, methodNo) => {
        serviceInterfaces.push({
          interface: `${serviceNo}${methodNo}`,
          method: `${service.constructor.name}.${interfas.method.name}()`,
          desc: interfas.methodDesc
        })
      })
    })

    ctx.body = serviceInterfaces
  }

  init () {
    if (isDevMod()) {
      this.addServiceInterface({
        methodNo: '000',
        method: this.listService,
        methodDesc: 'list all service interfaces'
      })
      addExcludeInterface(this.serviceNo)
    }
  }
}

export default new DocService(ServiceNo.doc)
